package core.manager
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class AnimationManager
	{
		public function AnimationManager()
		{
		}
		
		private static var _instance:AnimationManager;
		
		public static function get instance():AnimationManager {
			if(_instance == null){
				_instance = new AnimationManager();
			}
			return _instance;
		}
		
		public var delay:int = 50;
		public function start():void {
			var timer:Timer = new Timer(delay);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
			timer.start();
		}
		
		private var _items:Array = [];
		
		public function addItem(value:Object):void {
			this._items.push(value);
		}
		
		public function onTimer(event:TimerEvent):void {
			for each(var item:Object in this._items){
				if(item.hasOwnProperty("isRunning")){
					if(item.isRunning == true){
						item.update();
					}
				}else {
					item.update();
				}
			}
		}
		
		public function removeItem(value:Object):void {
			var index:int = this._items.indexOf(value);
			if(index != -1){
				this._items.splice(index,1);
			}
		}
	}
}